#coding=utf-8
'''
Created on 2013-9-8

@author: Ben
战斗
'''

from ..common import Command, RequestModel, Logger
from ..common.SocketService import gameSocketService
import WarData

'''
请求察看战斗
'''
class WarBattlePermitRequest(RequestModel.RequestModel):

    def setCommand(self):
        self.command = Command.BATTLE_PERMIT
        
    def setParams(self, generalId):
#         Logger.log('请求进入general:' + str(generalId) + '所在的战场', output = True)
        self.params = 'generalId=' + str(generalId) +'&targetId=0&reserve=0&type=3'
    
    def onReceive(self, data):
        if 'battle' in data and data['battle']:
            if 'battleId' in data:
                Logger.log('成功进入战场:' + data['battleId'], output = True)
                WarData.battleId = data['battleId']
        else:
            Logger.log('战场不存在', output = True)
                
'''
获取战斗信息
'''
class WarGetInfoRequest(RequestModel.RequestModel):
    
    def setCommand(self):
        self.command = Command.GET_WAR_INFO
        
    def setParams(self, generalId):
#         Logger.log('获取general:' + str(generalId) + '所在战场信息', output = True)
        self.params = 'generalId=' + str(generalId) +'&targetId=0&terrainType=1&type=3'
        
    def onReceive(self, data):
        Logger.log('成功获取战场信息', output = True)
        WarData.init(data)
        
'''
战场借兵
'''
def phantom():
    command = Command.WAR_PHANTOM
    params = 'battleId=' + str(WarData.battleId)
    Logger.log('请求在战场:' + str(WarData.battleId) + '借兵', output = True)
    gameSocketService.send(command, params, phantomCallback)
    
'''
战场借兵回调函数
'''
def phantomCallback(data):
    if 'gName' in data:
        Logger.log('借兵成功:' + data['gName'], output = True)